package examples.mail;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.io.Util;
import org.apache.commons.net.smtp.SMTPClient;
import org.apache.commons.net.smtp.SMTPReply;
import org.apache.commons.net.smtp.SimpleSMTPHeader;

public class SMTPUtil {

	public static void main(String[] args) throws Exception {

		String toserver = "mx1.qq.com";

		String mailserver = "m13-97.163.com";

		String from = "����ָ��<baizhiup@163.com>";

		String to = "nice2mu@qq.com";

		String subject = "��������,������й©!";
		String htmlcontent = "ddddddddd";// "<A href=\"http://s.click.taobao.com/t_8?e=3D7HZ6jHSTbIWchi2irVZeSulXVLyPJjWL=FDBQXHNg66lBjg%3D%3D&amp;p=3Dmm_28188379_0_0\"><IMG src=\"http://boluozhiwen.svfree.net/up.html\"></A>";

		// String mail = MailBuild.build(mailserver, from, to,
		// subject,htmlcontent);

		// System.out.println(mail);

		// SMTPMail.send(from, to, toserver, mailserver, mail);
	}

	public static void testUser(String from, String to, String toserver, String mailserver) throws Exception {

		SMTPClient client = null;

		try {

			client = new SMTPClient();
			//client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
			client.connect(toserver);

			client.setConnectTimeout(5000);
			client.setSoTimeout(5000);

			if (!client.login(mailserver)) {
				throw new Exception(client.getReplyString());
			}

			if (!client.setSender(from)) {
				throw new Exception(client.getReplyString());
			}

			if (!client.addRecipient(to)) {
				throw new Exception(client.getReplyString());
			}
			
			
			
			client.quit();

		 
		} catch (Exception e) {
			throw e;
		}finally{
			if (client != null) {
				client.disconnect();
				
			}
		}

	}

}
